package com.hopu.service.Impl;

import com.hopu.mapper.IEmpMapper;
import com.hopu.pojo.Dept;
import com.hopu.pojo.Emp;
import com.hopu.service.IEmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EmpServiceImpl implements IEmpService {

    @SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection")
    @Autowired
    private IEmpMapper iEmpMapper;

    @Override
    public List<Emp> findAll() throws Exception {
        return iEmpMapper.findAll();
    }

    @Override
    public List<Emp> findById(Integer eid,Integer did) throws Exception {
        return iEmpMapper.findById(eid,did);
    }

    @Override
    public int update_emp(Integer eid, String ename) {
        Emp e = new Emp();//封装
        e.setEid(eid);
        e.setEname(ename);
        int i = iEmpMapper.update_emp(e);
        if (i == 1) {
            System.out.println("修改成功");
        }else {
            System.out.println("修改失败");
        }
        return i;
    }

    @Override
    public int save(String ename, Integer did) throws Exception {
        Emp e = new Emp();//封装
        e.setEname(ename);
        e.setDid(did);
        int i = iEmpMapper.save(e);
        if (i == 1) {
            System.out.println("新增成功");
        }else {
            System.out.println("新增失败");
        }
        return i;
    }

    @Override
    public int delete_emp(Integer eid) throws Exception {
        int i = iEmpMapper.delete_emp(eid);
        if (i == 1) {
            System.out.println("删除成功");
        }else {
            System.out.println("删除失败");
        }
        return i;
    }
}
